package com.ruoyi.eam.service.impl;

import com.ruoyi.eam.doman.*;
import com.ruoyi.eam.mapper.*;
import com.ruoyi.eam.service.SummaryStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class SummaryStatusServiceImpl implements SummaryStatusService {

    @Resource
    private EamStockMapper stockMapper;
    @Resource
    private EamManageHMapper manageHMapper;
    @Resource
    private EamReturnHMapper returnHMapper;
    @Resource
    private EamChgHMapper chgHMapper;
    @Resource
    private EamLoanbackHMapper loanbackHMapper;
    @Resource
    private EamAllotHMapper allotHMapper;
    @Resource
    private EamMaintainMapper eamMaintainMapper;
    @Resource
    private UserMapper userMapper;


    /*查询所有单中待审核的单号*/
    @Override
    public List<SummaryAsset> querySummaryStatus() {
        List<SummaryAsset> list = new ArrayList<>();
        //入库
        EamStock stock = new EamStock();
        stock.setAuditType(3L);
        List<EamStock> stocks = stockMapper.selectEamStockList(stock);
        if(stocks.size() != 0){
            for (EamStock eamStock : stocks) {
                SummaryAsset summaryAsset = new SummaryAsset();
                summaryAsset.setCode(eamStock.getStockcode());
                summaryAsset.setName(userMapper.selectUserByUserId(eamStock.getCreator()).getNickName());
                summaryAsset.setCreateTame(eamStock.getCreateTime());
                summaryAsset.setType(1);
                list.add(summaryAsset);
            }
        }
        //领用
        EamManageH manageH = new EamManageH();
        manageH.setAuditState(1L);
        List<EamManageH> manageHS = manageHMapper.selectEamManageHList(manageH);
        if(manageHS.size() != 0){
            for (EamManageH manageH1 : manageHS) {
                SummaryAsset summaryAsset = new SummaryAsset();
                summaryAsset.setCode(manageH1.getAssetCode());
                summaryAsset.setName(userMapper.selectUserByUserId(manageH1.getCreator()).getNickName());
                summaryAsset.setCreateTame(manageH1.getCreateTime());
                summaryAsset.setType(2);
                list.add(summaryAsset);
            }
        }
        //退还
        EamReturnH returnH = new EamReturnH();
        returnH.setAudiStatus(1L);
        List<EamReturnH> returnHS = returnHMapper.selectEamReturnHList(returnH);
        if(returnHS.size() != 0){
            for (EamReturnH returnH1 : returnHS) {
                SummaryAsset summaryAsset = new SummaryAsset();
                summaryAsset.setCode(returnH1.getReturnCode());
                summaryAsset.setName(userMapper.selectUserByUserId(returnH1.getPrepared()).getNickName());
                summaryAsset.setCreateTame(returnH1.getCreateTime());
                summaryAsset.setType(3);
                list.add(summaryAsset);
            }
        }
        //变更
        EamChgH chgH = new EamChgH();
        chgH.setReceiptsStatus(3L);
        List<EamChgH> chgHS = chgHMapper.selectEamChgHList(chgH);
        if(chgHS.size() != 0){
            for (EamChgH chgH1 : chgHS) {
                SummaryAsset summaryAsset = new SummaryAsset();
                summaryAsset.setCode(chgH1.getAlterationOdd());
                summaryAsset.setName(userMapper.selectUserByUserId(chgH1.getPrepared()).getNickName());
                summaryAsset.setCreateTame(chgH1.getCreateTime());
                summaryAsset.setType(4);
                list.add(summaryAsset);
            }
        }
        //借用归还
        EamLoanbackH loanbackH = new EamLoanbackH();
        loanbackH.setReceiptsStatus(3L);
        List<EamLoanbackH> loanbackHS = loanbackHMapper.selectEamLoanbackHList(loanbackH);
        if(loanbackHS.size() != 0){
            for (EamLoanbackH loanbackH1 : loanbackHS) {
                SummaryAsset summaryAsset = new SummaryAsset();
                summaryAsset.setCode(loanbackH1.getLoanCode());
                summaryAsset.setName(userMapper.selectUserByUserId(loanbackH1.getCreator()).getNickName());
                summaryAsset.setCreateTame(loanbackH1.getCreateTime());
                summaryAsset.setType(5);
                list.add(summaryAsset);
            }
        }
        //调拨
        EamAllotH allotH = new EamAllotH();
        allotH.setReceiptsStatus(3L);
        List<EamAllotH> allotHS = allotHMapper.selectEamAllotHList(allotH);
        if(allotHS.size() != 0){
            for (EamAllotH allotH1 : allotHS) {
                SummaryAsset summaryAsset = new SummaryAsset();
                summaryAsset.setCode(allotH1.getAllotOdd());
                summaryAsset.setName(userMapper.selectUserByUserId(allotH1.getCreator()).getNickName());
                summaryAsset.setCreateTame(allotH1.getCreateTime());
                summaryAsset.setType(6);
                list.add(summaryAsset);
            }
        }
        //维修
        EamMaintain maintain = new EamMaintain();
        maintain.setReceiptsStatus(3L);
        List<EamMaintain> maintains = eamMaintainMapper.selectEamMaintainList(maintain);
        if(maintains.size() != 0){
            for (EamMaintain maintain1 : maintains) {
                SummaryAsset summaryAsset = new SummaryAsset();
                summaryAsset.setCode(maintain1.getMaintainCode());
                summaryAsset.setName(userMapper.selectUserByUserId(maintain1.getCreator()).getNickName());
                summaryAsset.setCreateTame(maintain1.getCreateTime());
                summaryAsset.setType(7);
                list.add(summaryAsset);
            }
        }
        return list;
    }
}
